package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.AuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author XHui
 * @Since 2024/2/5 14:39
 * @Version 1.0
 */
@Api("文章作者controller")
@RestController
@RequestMapping("/api/v1/author")
public class AuthorController {

    // 注入依赖
    @Resource
    private  AuthorService authorService;

    // 根据用户id查询作者信息
    @GetMapping("/findByUserId/{userId}")
    public ResponseResult find(@PathVariable("userId") Integer userId) {
        ApAuthor apAuthor = authorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId, userId));
        return ResponseResult.okResult(apAuthor);
    }

    // 保存作者信息
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        authorService.save(apAuthor);
        return ResponseResult.okResult();
    }
}
